package com.fms.gui.templateCreator.components.button;

import junit.framework.TestCase;

import org.jmock.Expectations;
import org.jmock.Mockery;

import com.fms.model.domain.FlowSheet;
import com.fms.model.factory.IFlowSheetFactory;
import com.fms.model.repository.IFlowSheetRepository;


public class CreateSheetTemplateButtonTest extends TestCase
{
	public void testCreateSheetButton()
	{
		Mockery mock = new Mockery();
		
		final FlowSheet sheet = new FlowSheet("");
		final IFlowSheetFactory maker = mock.mock(IFlowSheetFactory.class);
		final IFlowSheetRepository repo = mock.mock(IFlowSheetRepository.class);		
		
		mock.checking(new Expectations() {{
			oneOf(maker).newSheet(); will(returnValue(sheet));
			oneOf(repo).saveAsNew(with(equal(sheet)));
		}});
		
		
		CreateSheetTemplateButton button = new CreateSheetTemplateButton(maker, repo);
	
		button.doClick();
	
	
		mock.assertIsSatisfied();
	}
	
	
	
	
	public void testCreateSheetButtonNullSheet()
	{
		Mockery mock = new Mockery();
		
		final IFlowSheetFactory maker = mock.mock(IFlowSheetFactory.class);
		final IFlowSheetRepository repo = mock.mock(IFlowSheetRepository.class);		
		
		mock.checking(new Expectations() {{
			oneOf(maker).newSheet(); will(returnValue(null));
			never(repo).saveAsNew(with(any(FlowSheet.class)));
		}});
		
		
		CreateSheetTemplateButton button = new CreateSheetTemplateButton(maker, repo);
		
		button.doClick();
		
		mock.assertIsSatisfied();
	}
	
	
	
	


}
